<template>
	<tm-app color="#EFEFEF">
		<navbar-module title="治疗工单"/>
		<view class="flex flex-end">

		</view>
		  <view v-if="itemData.length>0" class="firstDom">
		  <view class="listDom">
			  <tm-scrolly :refresher="false" v-model="pull" v-model:bottom-value="bottomFresh" @refresh="refresh" @bottom="refreshBottom" _style="height:90%">
			  		<was-work-list-item :data="{}" :url="`/pages/treatment/details/details?data=${encodeURIComponent(JSON.stringify(item))}`" v-for="item in itemData" :key="item.code" :code="item.content" icon="tmicon-new-releases" titleColor="red">
			  			<tm-text :label="`猪仔名称：${item.pig.name}`" class="text" :fontSize="32"/>
			  			<tm-text :label="`所属猪圈：${item.pig.pigsty.name}`" class="text" :fontSize="32"/>
			  			<!-- <tm-text :label="`治疗类型：${item.content}`" class="text"/> -->
			  			<tm-text :label="`治疗人员：${item.staff.name}`" class="text" :fontSize="32"/>
			  			<tm-text :label="`治疗时间：${item.completeTime} `" class="text text-border" color="#999" :font-size="28"/>
			  		</was-work-list-item>
			  </tm-scrolly>
		  </view>
			  
		  </view>
		  <view v-else>
			  <no-data :flag="loadFlag"/>
		  </view>

			<view style="position: fixed;bottom:0; width: 750rpx;">
				<tm-button :margin="[20]" block size="large" :linear-color="['#FADC19', '#23C343']" :round="16" linear="right" :fontSize="34" :height="90" :shadow="0" label="发起治疗" @click="gotoPage('/pages/treatment/form/form')"/>
			</view>
	</tm-app>
</template>

<script setup lang="ts">
	import {ref} from 'vue'
	import {onShow} from '@dcloudio/uni-app'
	import { finishTreat } from '../../index/resource/http'


	const loadFlag = ref(false)
	const itemData = ref([])
	
	const params = {pageNo:1,pageSize:10}
	const bottomFresh = ref(false)
	const pull = ref(false)
	const bottomFlag = ref(true)

	onShow(()=>{
		loadFlag.value = false
		getData()
	})

	const getData = async ()=>{
		itemData.value = []
		params.pageNo = 1
		const {data} = await finishTreat(params)
		itemData.value = data.records
		loadFlag.value = true
		
		bottomFlag.value = data.hasNext
	}

	const gotoPage = (url)=>{
		uni.navigateTo({
			url,
		})
	}
	
	const refreshBottom = async () => {
		if(bottomFlag.value){
			bottomFresh.value = true
			params.pageNo++
			const {data} = await finishTreat(params)
			itemData.value.push(...data.records)
			
			bottomFresh.value = false
			bottomFlag.value = data.hasNext
		}
	}
	
	const refresh = async () => {
		setTimeout(()=>{
			pull.value = false
		})
	}
</script>
<style>
</style>
